package com.andaily.web.controller.mobile.thing;

import com.andaily.domain.dto.thing.ThingArchiveDto;
import com.andaily.service.ThingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/thing/archive")
public class ThingArchiveController {

    private static Logger logger = LoggerFactory.getLogger(ThingArchiveController.class);

    @Autowired
    private ThingService thingService;


    @RequestMapping("overview")
    public String overview(ThingArchiveDto thingArchiveDto, Model model) throws Exception {
        thingArchiveDto = thingService.loadThingArchiveDto(thingArchiveDto);
        model.addAttribute("thingArchiveDto", thingArchiveDto);
        return "thing/thing_archive_overview";
    }

    @RequestMapping("overview/more")
    public String more(ThingArchiveDto thingArchiveDto, Model model) throws Exception {
        thingArchiveDto = thingService.loadThingArchiveDto(thingArchiveDto);
        model.addAttribute("thingArchiveDto", thingArchiveDto);
        return "thing/thing_archive_overview_more";
    }

    @RequestMapping("archive_confirm")
    public String archiveConfirm(String data, Model model) {
        model.addAttribute("data", data);
        return "thing/thing_archive_confirm";
    }

    @RequestMapping("archive")
    public String archive(String[] guids) {
        logger.debug("Archive things: {}", guids);
        final boolean result = thingService.archiveThings(guids);
        return "redirect:overview?result=" + result;
    }


}
